package com.lsl.test1;

/**
 * @author lishuailong
 * @create 2020-07-03 17:11
 */
public class TestD {
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Earth.getEarth());
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Earth.getEarth());
            }
        }).start();

    }

}

class Earth{
    private static Earth earth;

    private Earth() {
    }

    public static Earth getEarth() {
        synchronized (Earth.class){
            if (earth==null){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                earth=new Earth();
            }
      }

        return earth;
    }
}
